<template>
	<view class="container">
		
		<view v-if="isLogin" v-for="(course,index) in courses" :key="course.id" class="head-container">
			<image :src="course.cover" mode="aspectFill" class="img"></image>
			<text class="head-name">{{course.name}}</text
			<text class="head-nick">{{nick+"老师"}}</text>
			<text class="head-disc">{{course.disc}}</text>
			
			<text class="head-Chapter">共{{course.countChapter}}章</text>
			<text class="head-number">共{{course.countStudent}}人</text>
			<text v-if="course.open == true" class="head-open"></text>
			<text v-if="course.open == true" class="open-text">✔</text>
		</view>
	
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				isLogin: false,
				courses: [],
				nick: '',
				
			}
		},
		onLoad() {
			this.courseAll()
		},
		mounted() {
			this.isLogin = app.globalData.token.length > 0
			this.nick = app.globalData.nickName
			if (!this.isLogin) {
				delta = 2
				this.$refs.login.show()
			}
		},
		onPullDownRefresh() {
			this.courses = [],
				console.log("执行了下拉刷新")
			
			this.courseAll()
			uni.stopPullDownRefresh()
		},
		methods: {

			courseAll() {
				let url = this.$params.host + this.$params.teacher_course
				let data = {
					token: app.globalData.token,
					id: app.globalData.uid
				}
				this.$request.glyAllget(url, data, res => {
					console.log(res)
					res.data.forEach(b => {
						if (!b.cover.startsWith('http')) {
							b.cover = this.$params.host + b.cover
						}
					})
					this.courses = res.data
				});
			},
		
			
		}
	}
</script>

<style>
	@import url("courseGL.css");
</style>
